{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e56f526c-9296-4694-bfd3-f84b19ba8ef3",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "from sklearn.preprocessing import MinMaxScaler\n",
    "import tensorflow as tf\n",
    "from joblib import load\n",
    "\n",
    "class MW(object):\n",
    "    def __init__(self):\n",
    "        self.loaded_model = tf.keras.models.load_model('timing/my_model.keras')\n",
    "        self.scaler = load('timing/scaler.joblib')\n",
    "\n",
    "    def get_hourly_trend(self):\n",
    "        n_steps = 7\n",
    "        df_pivot = pd.read_csv('timing/scenic_data.csv')\n",
    "        x_values = df_pivot.iloc[-n_steps:]\n",
    "        x_values.iloc[-1, x_values.columns.get_loc('count')] = 0\n",
    "        latest_data = x_values.values  # 取最后七天数据\n",
    "        latest_data = latest_data.reshape(1, n_steps, latest_data.shape[1])\n",
    "\n",
    "        # 预测未来趋势\n",
    "        predicted = self.loaded_model.predict(latest_data)\n",
    "        predicted_counts = self.scaler.inverse_transform(predicted)  # 反归一化\n",
    "        predicted_counts[predicted_counts < 0] = 0\n",
    "        hourly_trend = predicted_counts[0].astype(int).tolist()\n",
    "        print(hourly_trend)\n",
    "\n",
    "if __name__ == '__main__':\n",
    "    nn = NN()\n",
    "    nn.get_hourly_trend()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
